<?php
//DB Created by Rich L. a member in service in Northern Delaware.  Please feel free to share this code wherever it may be useful to alcholoics.  Should you have questons please contact me at sobernerd@gmail.com
if ($_SESSION['logged_in'] == 0) {
	require ('../../admin/security_check.php');
} else {
	if ($_POST)	{
	processTable('meeting_types');
	}
/* location query */
$sql = "SELECT meetings.mtg_type_id, meeting_types.id as id, meeting_types.code AS code, meeting_types.description AS description, meeting_types.explanation AS explanation, count(meetings.mtg_type_id) AS counter
	FROM meetings
	RIGHT JOIN meeting_types ON meeting_types.id = meetings.mtg_type_id
	GROUP BY meetings.mtg_type_id, meeting_types.code
	ORDER BY code ASC";

$result = mysql_query($sql)  or die(mysql_error());
$num_rows = mysql_num_rows($result);
?>
<script language="javascript" type="text/javascript">
var table = 'meeting_types';

$(document).ready(function(){ 
	$('.meetingEdit').editable('inlineEdit.php', {
			 indicator : 'Saving...',
			 tooltip   : 'Click to edit...',
			 style     : 'display: inline',
			 submitdata : {table: table},
			 submit    : '<span>&nbsp;&nbsp;<input type="submit" value="OK"></span>',
			 callback : function(value, settings) {
				$(this).next('.message').show();
				$(this).next('.message').html('');
         		$(this).next('.message').append('Updated');
				$(this).next('.message').fadeOut(2000);
    		 }
     });
	 var sum = 0;
	 var thisNum = 0;

	 $('.meetingTypeMtgCount').each(function() {
		thisNum = parseInt($(this).html());
		if(thisNum == 0) {
        	sum += 1;
			$(this).closest('tr').attr('bgcolor','#FF6666');
		}
    });
	$('#wrapper div.main_content table.tabletext thead.meetingHeader tr.titleRow th h3').append('&nbsp;&nbsp; - &nbsp;&nbsp;('+sum+'&nbsp; with no meetings)');
});
</script>
<table class="tabletext tabletype">
      	<thead class="meetingHeader">
          <tr class="titleRow">
            <th colspan="4"><h3>Meeting Types&nbsp;&nbsp;&nbsp;(<?php echo $num_rows ?>)</h3></th>
          </tr>
          <tr class="alternateRow">
            <th>Code</th>
            <th>Description</th>
            <th id="numMtgsHeader"># of Meetings</th>
      		<th></th>
          </tr>
        </thead>
<?php		
// Get each row of data on each iteration until
// there is no more rows
$i = 0;
/* output data in rows */ 
while ($row = mysql_fetch_assoc($result))	{
   
if ($i%2 == 0) {
$rowcolor="$reprowcolor";
} else {
$rowcolor="white";
}
?>
<tr bgcolor="<?php echo $rowcolor?>">
  <td><div class="meetingType"><?php echo $row[code]?></div></td>
  <td><div class="meetingType"><?php echo $row[description]?></div></td>
  <td><div class="meetingTypeMtgCount"><?php echo $row['counter'];?></div></td>
    <td><div class="meetingDelete"> 
    		<a href="meetings.php?page=types_edit&id=<?php echo $row['id']?>&return_to=meetings.php?page=types"><img src="../images/edit_button.png"></a>
        	<a href="deleteform.php?id=<?php echo $row['id']?>&table=meeting_types&return_to=meetings.php?page=types"><img src="../images/delete_button.png"></a>
        </div>
    </td>
</tr>
<?php
$i++;}

}
mysql_close($conn);?>
</table>